<?php
/**
 * 腾讯股票处理类
 * v0.0.1
 * Created by PhpStorm.
 * User: Sunwu
 * Date: 2017/9/20
 * Time: 21:30
 */
require_once "./Curl.class.php";
class Stock{
    /**
     * 将qq返回的数据处理成数组
     * @param $data
     * @return array 数组
     */
    private function splitQQStockResponse($data){
        $data=explode('~',$data);
        return $data;
    }

    /**
     * 根据传入的数组获取指定的信息
     * @param $data
     * @return array
     */
    public function getAppointInfo($stockCode){
        $data=$this->getInfoByStockCode($stockCode);
        $data=$this->splitQQStockResponse($data);
        $returnArr=array();
        $returnArr['当前价格']=$data['3'];
        $returnArr['今开']=$data['5'];
        $returnArr['最高价']=$data['33'];
        $returnArr['52周最高价']=$data['48'];
        $returnArr['昨收']=$data['4'];
        return $returnArr;
    }


    /**
     * 根据股票代码获取股票信息
     * @param $code
     */
    public function getInfoByStockCode($code){
        $codeArr=array('sh','sz','hk');
        $usCode='us';
        $pattUs='//';
        $url="http://qt.gtimg.cn/q=";
        for ($i=0;$i<3;$i++){
            $tarUrl=$url.$codeArr[$i].$code;
            echo "-->".$tarUrl."\r\n";
            $remodeDate=Curl::doGet($tarUrl);
            if(strlen($remodeDate)>20){
                return $remodeDate;
            }
        }
        return false;

    }
}

$stock=new Stock();
$stockCode="00700";
$res=$stock->getAppointInfo($stockCode);
print_r($res);